package com.bob.imdservice.aidl;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

import com.bob.imdservice.socket.ConnectServer;

import java.io.IOException;

public class IMDService extends Service {

    private ConnectServer mConnectServer;

    public IMDService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        System.out.println("---onCreate()");
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        System.out.println("---onBind()");
        try {
            mConnectServer = new ConnectServer();
            mConnectServer.service();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new RemoteBinder();
    }

    class RemoteBinder extends SocketMDService.Stub{

        @Override
        public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {

        }

        @Override
        public void connectServer() throws RemoteException {
            System.out.println("打开Socket");
            try {
                mConnectServer = new ConnectServer();
                mConnectServer.service();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
